import hashlib
import json
import time
from http.client import responses

import requests
import os

def apiGet():
    url = "http://192.168.1.37:8080/pinter/com/getSku"

    params={"id":1}
    headers = {
      'Content-Type': 'application/x-www-form-urlencoded'
    }

    # response = requests.request("POST", url, headers=headers, params=params)
    response = requests.get(url,params=params)
    # print(response.text)
    print(response.json())


def apiPost():
    url = "http://192.168.1.37:8080/pinter/com/login"

    data = {"userName":"admin","password":"123456"}
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded'
    }

    # response = requests.request("POST", url, headers=headers, data=data)
    response = requests.post(url,data=data)

    print(response.text)
    print(type(response.json()['code']))
def api_json():
    url = "http://192.168.1.37:8080/pinter/com/register"
    json = {"userName":"test","password":"1234","gender":1,"phoneNum":"110","email":"beihe@163.com","address":"Beijing"}
    response = requests.post(url,json=json)
    print(response.text)
    print(response.json()["code"])

def api_banklogin2_json():
    url = "http://192.168.1.37:8080/pinter/bank/api/login2"
    data = {"userName": "admin", "password": "123456"}
    response = requests.post(url, data)
    print(response.json()["data"])
    return response.json()["data"]

def api_bankquery_json(token):
    print('tokens',token)
    url = "http://192.168.1.37:8080/pinter/bank/api/query2"
    headers = {
        'testfan-token':token
    }
    params = {"userName":"admin","password":"123456"}
    response = requests.get(url,params=params,headers=headers)
    print(response.text)
    # print(response.json()["code"])
def api_cookies():
    url = "http://192.168.1.37:8080/pinter/bank/api/login"
    data= {
        "userName":"admin",
        "password":"1234"
    }
    headers = {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
    # response = requests.request("POST", url, headers=headers, params=params)
    response = requests.post(url,data = data)
    print('res',response)
    cookies = response.cookies
    print('cookies',cookies)
    url2 = "http://192.168.1.37:8080/pinter/bank/api/query"
    params2 = {"userName":"admin"}
    response = requests.get(url2,params=params2,cookies=cookies)
    print(response.json())
def api_bank_login():
    url = 'http://192.168.1.37:8080/pinter/bank/api/login'
    data = {"userName":"test","password":"1234"}
    response = requests.post(url,data=data)
    print(response.cookies)
    cookies = response.cookies
    url2 = 'http://192.168.1.37:8080/pinter/bank/api/query'
    params = {'userName':'test'}
    response = requests.get(url2,params=params,cookies=cookies)
    print(response.json())
def api_bank_login2():
    url = 'http://192.168.1.37:8080/pinter/bank/api/login2'
    data = {"userName":"test","password":"123456"}
    response = requests.post(url,data)
def api_file_upload():
    url ='http://192.168.1.37:8080/pinter/file/api/upload2'
    path = "__init__.py"
    with open(path,'r',encoding="utf-8") as file:
        files = {"file":(path,file)}
        response = requests.post(url,files=files)
        print(response.text)
def api_file_download():
    url = 'http://192.168.1.37:8080/pinter/file/api/download'
    params = {"id":9}
    response = requests.get(url,params=params)
    print(response.text)
def apt_md5():
    time.time()
if __name__ == '__main__':
    # apiGet().
    # apiPost()
    # api_json()
    # api_banklogin2_json()
    # token = api_banklogin2_json()
    # print('werew',token)
    # api_bankquery_json(token)
    # api_cookies()
    # api_bank_login()
    # api_file_upload()
    # api_file_download()
    print(int(time.time()*1000))
    mytime = int(time.time()*1000)
    tel = '18091839999'
    optcode = 'testfan'
    data = tel + optcode +str(mytime)
    print(data)
    m = hashlib.md5(data.encode())
    mysign = m.hexdigest()
    print(m.hexdigest())
    url = "http://192.168.1.37:8080/pinter/com/userInfo"
    json = {"phoneNum":tel,"optCode":optcode,"timestamp":mytime,"sign":mysign}
    response = requests.post(url,json=json)
    print(response.text)